package refect;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class FlashChar {

    private String palette;
    private String canvasBgAlpha;
    private String caption;
    private String shownames;
    private String numberPrefix;
    private String SNumberSuffix;
    private String NumberSuffix;
    private String PYAxisValuesDecimals;
    private String connectNullData;
    private String decimals;
    private String showBorder;
    private String borderColor;
    private String pmaxColWidth;
    private String PYAxisName;
    private String SYAxisName;
    private String pnumDivLines;
    private String formatNumberScale;
    private String baseFontSize;
    private String rotateLabels;
    private String slantLabels;
    private Category categories;
    private List<DataSet> dataset = new ArrayList<DataSet>();

    class Category {
        private List<String> lables = new ArrayList<String>();

        public List<String> getLables() {
            return lables;
        }

        public void setLables(List<String> lables) {
            this.lables = lables;
        }

        public void addLables(String str) {
            this.lables.add(str);
        }

        public void removeLables(int index) {
            this.lables.remove(index);
        }

        public void removeLables(String o) {
            this.lables.remove(o);
        }

    }
    
    class DataSet {
        private String seriesName;
        private String showValues;
        private List<String> values = new ArrayList<String>();

        public String getSeriesName() {
            return seriesName;
        }

        public void setSeriesName(String seriesName) {
            this.seriesName = seriesName;
        }

        public String getShowValues() {
            return showValues;
        }

        public void setShowValues(String showValues) {
            this.showValues = showValues;
        }

        public List<String> getValues() {
            return values;
        }

        public void setValues(List<String> values) {
            this.values = values;
        }

        public void addValues(String str) {
            this.values.add(str);
        }

        public void removeValues(int index) {
            this.values.remove(index);
        }

        public void removeValues(String o) {
            this.values.remove(o);
        }
    }

    public String getPalette() {
        return palette;
    }

    public void setPalette(String palette) {
        this.palette = palette;
    }

    public String getCanvasBgAlpha() {
        return canvasBgAlpha;
    }

    public void setCanvasBgAlpha(String canvasBgAlpha) {
        this.canvasBgAlpha = canvasBgAlpha;
    }

    public String getCaption() {
        return caption;
    }

    public void setCaption(String caption) {
        this.caption = caption;
    }

    public String getShownames() {
        return shownames;
    }

    public void setShownames(String shownames) {
        this.shownames = shownames;
    }

    public String getNumberPrefix() {
        return numberPrefix;
    }

    public void setNumberPrefix(String numberPrefix) {
        this.numberPrefix = numberPrefix;
    }

    public String getSNumberSuffix() {
        return SNumberSuffix;
    }

    public void setSNumberSuffix(String sNumberSuffix) {
        SNumberSuffix = sNumberSuffix;
    }

    public String getNumberSuffix() {
        return NumberSuffix;
    }

    public void setNumberSuffix(String numberSuffix) {
        NumberSuffix = numberSuffix;
    }

    public String getPYAxisValuesDecimals() {
        return PYAxisValuesDecimals;
    }

    public void setPYAxisValuesDecimals(String pYAxisValuesDecimals) {
        PYAxisValuesDecimals = pYAxisValuesDecimals;
    }

    public String getConnectNullData() {
        return connectNullData;
    }

    public void setConnectNullData(String connectNullData) {
        this.connectNullData = connectNullData;
    }

    public String getDecimals() {
        return decimals;
    }

    public void setDecimals(String decimals) {
        this.decimals = decimals;
    }

    public String getShowBorder() {
        return showBorder;
    }

    public void setShowBorder(String showBorder) {
        this.showBorder = showBorder;
    }

    public String getBorderColor() {
        return borderColor;
    }

    public void setBorderColor(String borderColor) {
        this.borderColor = borderColor;
    }

    public String getPmaxColWidth() {
        return pmaxColWidth;
    }

    public void setPmaxColWidth(String pmaxColWidth) {
        this.pmaxColWidth = pmaxColWidth;
    }

    public String getPYAxisName() {
        return PYAxisName;
    }

    public void setPYAxisName(String pYAxisName) {
        PYAxisName = pYAxisName;
    }

    public String getSYAxisName() {
        return SYAxisName;
    }

    public void setSYAxisName(String sYAxisName) {
        SYAxisName = sYAxisName;
    }

    public String getPnumDivLines() {
        return pnumDivLines;
    }

    public void setPnumDivLines(String pnumDivLines) {
        this.pnumDivLines = pnumDivLines;
    }

    public String getFormatNumberScale() {
        return formatNumberScale;
    }

    public void setFormatNumberScale(String formatNumberScale) {
        this.formatNumberScale = formatNumberScale;
    }

    public String getBaseFontSize() {
        return baseFontSize;
    }

    public void setBaseFontSize(String baseFontSize) {
        this.baseFontSize = baseFontSize;
    }

    public String getRotateLabels() {
        return rotateLabels;
    }

    public void setRotateLabels(String rotateLabels) {
        this.rotateLabels = rotateLabels;
    }

    public String getSlantLabels() {
        return slantLabels;
    }

    public void setSlantLabels(String slantLabels) {
        this.slantLabels = slantLabels;
    }

    public Category getCategories() {
        return categories;
    }

    public void setCategories(Category categories) {
        this.categories = categories;
    }

    public List<DataSet> getDataset() {
        return dataset;
    }

    public void setDataset(List<DataSet> dataset) {
        this.dataset = dataset;
    }
    public void addDataset(DataSet str) {
        this.dataset.add(str);
    }

    public void removeDataset(int index) {
        this.dataset.remove(index);
    }

    public void removeDataset(DataSet o) {
        this.dataset.remove(o);
    }

    public String getName(Object o) throws IllegalArgumentException, IllegalAccessException{
    	StringBuilder chart = new StringBuilder();
    	Class clazz = o.getClass();
//      System.out.println("22"+o.getClass().getDeclaredField("this$0").get(o));
      Field[] fields = clazz.getDeclaredFields();
      if (fields.length < 1)
          return "";
      for (short j = 0; j < fields.length; j++) {
          Field field = fields[j];
          if (!field.isAccessible()) {
              field.setAccessible(true);
          }
          Object value = field.get(o);
          System.out.println("value:" + value);
          System.out.println("name:" + field.getName());
          System.out.println("type:" + field.getType());
          chart.append(field.getName() + "='" + (value == null ? "" : value) + "' ");
          System.out.println("getDeclaringClass:"    + field.getDeclaringClass());
          if (List.class.isAssignableFrom(field.getType())) {
              Type t = field.getGenericType();
              if (t instanceof ParameterizedType) {
                  Type[] arg = ((ParameterizedType) t).getActualTypeArguments();
                  System.out.println("arg:" + arg[0]);
                  Class z = (Class) arg[0];
                  System.out.println("z:" + z.getDeclaringClass());
                  Field[] tt = z.getDeclaredFields();
                  for (short k = 0; k < tt.length; k++) {
                      Field m = tt[k];
                      if (!m.isAccessible()) {
                          m.setAccessible(true);
                      }
                      System.out.println("z value =:" + m.getName());
                  }
              }
          }
      }
	return chart.toString();
}
    
    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException{
    	
    	FlashChar flashChar = new FlashChar();
    	
    	flashChar.getName(flashChar);
    }
}


